Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

import tarfile #62

Merged
merged 6 commits into from Aug 13, 2019
Merged

import tarfile #62

merged 6 commits into from Aug 13, 2019

Conversation

ghost
Copy link

@ghost ghost commented Jul 30, 2019

Signed-off-by: laven-s laven.s@ibm.com

const fileName = name + '.tar.gz';
let file = fs.createWriteStream(fileName);

await new Promise((resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we return the Promise here? It will be awaited by the caller

})
})
.catch(error => {
throw new Error('Extracting tar file failed');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should reject the error here?

const { exec } = require('child_process');
import request from 'request';

export async function importProjectFromTar(tarFile: string, name: string, dest: string): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we get rid of the await below this doesn't need to be a async function

@makandre
Copy link
Contributor

makandre commented Aug 1, 2019

@laven26 How are the changes coming along?

fs.removeSync(fileName);
});

resolve();
Copy link
Contributor

@makandre makandre Aug 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed something... this actually needs to go into exec callback above. And removeSync should have try/catch


if (err)
    return reject(err);

try {
    fs.removeSync(fileName); 
}
catch (err) {
   // probably just log this here.
}

resolve();

resolve();

})
.on('error', (error) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more concise syntax here can be `.on('error', reject);

@@ -47,6 +48,16 @@ export default class ProjectInitializer {
return this.initializeExistingProject();
}

async initializeProjectFromTar(
tarFile: string
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed return type here

@makandre
Copy link
Contributor

makandre commented Aug 1, 2019

LGTM

@sghung
Copy link
Contributor

sghung commented Aug 1, 2019

@rajivnathan can you help review this? Thank you

@sghung sghung removed the request for review from rajivnathan August 6, 2019 15:57
@sghung
Copy link
Contributor

sghung commented Aug 6, 2019

@hhellyer , can you help review this? Thank you

@sghung sghung requested a review from hhellyer August 6, 2019 20:43
Copy link
Contributor

@hhellyer hhellyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a rebase to bring it up to date as well as we've actually added the request module in the meantime. If you wanted to pull out the asyncHttpDownload or the execAsync function from #100 to a utility file that might be good but not essential.

@@ -42,7 +42,9 @@ export async function initializeProject(projectName: string, projectDirectory: s
const projectInitializer = new ProjectInitializer(projectName, projectDirectory);

try {
if (isGitCloneRequired(projectName, gitRepository)) {
if (gitRepository.endsWith("tar.gz")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that comfortable with overloading GIT_REPO to also mean "any url to a tar.gz". Can we just use a different env var and check if that was set or if GIT_REPO was set?

resolve();
});
})
.on('error', reject);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this remove the empty or partial file if the download fails? (e.g. on a bad url or github being down)

export function importProjectFromTar(tarFile: string, name: string, dest: string): Promise<void> {

const fileName = name + '.tar.gz';
const file = fs.createWriteStream(fileName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be an absolute filename, otherwise it will just be created in the current working directory (and I'm not sure exactly where that will be in all cases).

Copy link
Contributor

@hhellyer hhellyer Aug 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use /tmp not /app. /app exists in the initialiser pod but the initialiser code is run directly as an npm when we are in che and /app doesn't exist there.
(Also /tmp is a better location for temporary files.)

laven-s added 3 commits August 8, 2019 12:33
Signed-off-by: laven-s <laven.s@ibm.com>
Signed-off-by: laven-s <laven.s@ibm.com>
Signed-off-by: laven-s <laven.s@ibm.com>
`PROJ_NAME=${projectName}`,
`GIT_REPO=${gitInfo.repo}`,
);
}
Copy link
Contributor

@makandre makandre Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gitInfo.branch check below can go into this else block right? Since it would be applicable only for non-tarball scenario

`PROJ_NAME=${projectName}`,
`GIT_REPO=${gitInfo.repo}`,
);
if (gitInfo.repo.endsWith("tar.gz")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor nit: while you're making changes, could you make this check for .tar.gz? (add dot in the front)

Signed-off-by: laven-s <laven.s@ibm.com>
resolve();
});
})
.on('error', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's an err passed here you can then pass it to reject

laven-s added 2 commits August 9, 2019 13:16
Signed-off-by: laven-s <laven.s@ibm.com>
Signed-off-by: laven-s <laven.s@ibm.com>
@sghung
Copy link
Contributor

sghung commented Aug 13, 2019

Thanks for the reviews Andrew and Howard

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants